import { axiosInstance } from 'src/boot/axios'
import CommonConfig from 'src/assets/js/config'
import _ from 'lodash'

const bmsUrl = CommonConfig.bmsUrl + '/v1'
const baseUrl = CommonConfig.machinestatusUrl + '/v1'
const schemaUrl = CommonConfig.schemaUrl + '/v1'
const datacenterUrl = CommonConfig.datacenterUrl + '/v1'
const upmsUrl = CommonConfig.upmsUrl + '/v1'

/**
 * 获取新闻或公告
 */
export function getNewsList (params) {
  const newUrl = `${bmsUrl}/newsBulletin/list`

  return axiosInstance.get(newUrl, { params }).then((res) => {
    return Promise.resolve(res)
  })
}

/**
 * 公告弹框
 */
export function getNewsPopup (params) {
  const newUrl = `${bmsUrl}/newsBulletin/listPopup`

  return axiosInstance.get(newUrl, { params }).then((res) => {
    return Promise.resolve(res)
  })
}

export function getNotice (subsystemId) {
  const newUrl = `${bmsUrl}/subsystem/${subsystemId}/notices`

  return axiosInstance.get(newUrl).then((res) => {
    return Promise.resolve(res)
  })
}
/**
 * 查询新闻或公告
 * category 新闻-NEWS，公告-BULLETIN
 * pageNum 第几页
 * pageSize 每页多少条
 * **/
export function getNoticeNews (params) {
  const newUrl = `${bmsUrl}/newsBulletin/page`

  return axiosInstance.get(newUrl, { params }).then((res) => {
    return Promise.resolve(res)
  })
}

/**
 * 查询新闻中心列表
 * category 新闻-NEWS，公告-BULLETIN
 * pageNum 第几页
 * pageSize 每页多少条
 * **/
export function getNoticeNewsContent (params) {
  const newUrl = `${bmsUrl}/newsBulletin/pageAndContent`

  return axiosInstance.get(newUrl, { params }).then((res) => {
    return Promise.resolve(res)
  })
}

/**
 * 查询新闻或公告的详情
 * id
 * **/
export function getNoticeNewsDetail (id) {
  const newUrl = `${bmsUrl}/newsBulletin/detail/${id}`

  return axiosInstance.get(newUrl).then((res) => {
    return Promise.resolve(res)
  })
}

/**
 * 查询新闻或公告的详情
 * **/
export function getCountDevice () {
  const newUrl = `${baseUrl}/plant/count_device`

  return axiosInstance.get(newUrl).then((res) => {
    return Promise.resolve(res.data)
  })
}
/**
 * 查询新闻或公告的详情
 * **/
export function getRealTime () {
  const newUrl = `${baseUrl}/plant/real_time_status`

  return axiosInstance.get(newUrl).then((res) => {
    return Promise.resolve(res.data)
  })
}
/**
 * 根据车间ID 获取车间在用班制日期
 * id 车间ID
 * **/
export function getShiftsDate (id) {
  if (_.isNil(id)) {
    return
  }
  const newUrl = `${schemaUrl}/workshops/${id}/current_time/shift_date`

  return axiosInstance.get(newUrl).then((res) => {
    return Promise.resolve(res.data)
  })
}
/**
 * 根据车间ID 获取车间在用班制
 * id 车间ID
 */
export function getShifts (id) {
  if (_.isNil(id)) {
    return
  }
  const newUrl = `${schemaUrl}/workshop/${id}/shifts/use`

  return axiosInstance.get(newUrl).then((res) => {
    return Promise.resolve(res)
  })
}

/**
 * 获取用户详情信息
 */
export function getUserDetail () {
  const newUrl = `${datacenterUrl}/account/detail`

  return axiosInstance.get(newUrl).then((res) => {
    return Promise.resolve(res)
  })
}

/**
 * 列举应用
 * applicationStatus
 */
export function getApplications (params) {
  const newUrl = `${upmsUrl}/applications`

  return axiosInstance.get(newUrl, { params }).then((res) => {
    return Promise.resolve(res)
  })
}
